{# THE chat surface: thread, jump button, staged images, composer. The AI page's Chat section includes it and the drawer fetches it; there is one instance on a page at a time (the drawer empties while the Chat section shows), so the ids the scripts and the composer target stay unique. Needs: assistant, chat_path, messages, conversation_id, picker (the catalog is there to pick from), voice (how a spoken turn is heard, or none), approvals (the change queue's review list's URL, or none) and resolved_event (what a decision on a card sends), voices (the voice chip: voice with a database, for an operator), calls (live calls: ``offers_calls``), operator (a call's engine and cost are shown: the operator's controls), agent_url (the answering agent's editor, where the mount has one), composer (what a turn may carry: ``attachments.composer``). #} {% from "components/macros/icons.html" import icon %} {% from "components/macros/form.html" import button_classes, control %} {% from "components/macros/chat.html" import agent_chip, assistant_row, conversation_field, turn_head, voice_states %} {% from "partials/chat/_call.html" import call_bar, mic_states, phone, phone_states with context %}
{% if approvals %} {# Every card still waiting for the user, beside the thread, so a proposal is never lost with the conversation it was made in. #}
Waiting for your approval {# Fetched each time it is opened: most visits never open it. Fetched again, while open, when a card is decided anywhere on the page, so it never offers one already settled in the thread. #}
{% endif %}
    {% include "partials/chat/transcript.html" %}
{# Staged images live in the script (they ride the stream request, one turn only); the chips are drawn from that list. #} {# The markup the script clones: a staged image's chip, and the image viewer's body for the modal. Styling lives here, not in JS. #} {% if calls %} {# A card drawn mid-call, which the call announces: held at the foot of the thread until the saved turn redraws the thread. #} {# Her turn on a call as it runs: each step she takes, under her name, as a typed turn shows them, until the saved turn redraws the thread. #} {% endif %} {% if voice %}{{ mic_states() }}{% endif %}

{# Composer: the post appends the turn's bubbles; the script takes it from there. Enter sends, Shift+Enter inserts a newline. #}
{{ conversation_field(conversation_id) }} {# The chips are a row of their own above the box: beside it, in the drawer, they took the width the message needs. #}
{% if agent_url %}{{ agent_chip(assistant, agent_url) }}{% endif %} {% if picker %}{% endif %} {% if voices %}{% endif %}
{# Not ``required``: a message may be images alone (the route sends the house line); Send stays disabled until there is text or an image. #} {% if voice %} {# The microphone: records while pressed on, then sends what it heard as the message (static/js/voice.js). data-state is what the assistant is doing; voice_states draws it. #} {% endif %} {% if calls %} {# A live call (routes/partials/chat_live.py): the server holds the engine's session and carries the audio over this mount's socket. #} {% call phone(button_classes('default') ~ " data-[state=recording]:text-aegis-teal data-[state=recording]:border-aegis-teal data-[state=speaking]:text-aegis-teal data-[state=speaking]:border-aegis-teal data-[state=working]:text-aegis-teal data-[state=working]:border-aegis-teal") %}{{ phone_states() }}{% endcall %} {# The same call, full screen (stage.html), on the conversation open here (chat.js's ``conversationId``). #} {{ icon("zoom-in", "w-4 h-4") }} {% endif %}
{# In a call the composer row gives way to the call bar. #} {% if calls %}{{ call_bar() }}{% endif %}